/**
 * MIT License
 * 
 * Copyright (c) 2017 CaiDongyu
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package com.tunnel.server;

import com.tunnel.common.tunnel.TunnelDataQueueManager;
import com.tunnel.common.util.LogUtil;
import com.tunnel.common.util.StringUtil;
import com.tunnel.server.config.Config;
import com.tunnel.server.http.HttpServer;
import com.tunnel.server.tunnel.TunnelServer;

public class SRun {
	public static void main(String[] args) {
		String configFileUrl = "D:\\1-develop\\1-tool\\1-git\\2-repo\\tunnel\\tunnel-server\\src\\main\\resources\\sys.properties";
		if(args != null && args.length > 0){
			configFileUrl = args[0];
		}
		
		if(StringUtil.isEmpty(configFileUrl)){
			LogUtil.error("请指定tunnel-server配置文件");
			System.exit(0);
		}else{
			Config.init(configFileUrl);
		}
		//启动消息队列，自带心跳
		TunnelDataQueueManager.startTunnelDataQueue("Tunnel-Server", true);
		
		try {
			new TunnelServer().start();
		} catch (Exception e) {
			LogUtil.error(e);
		}
		
		if(Config.HTTP_SERVER_PORT > 0){
			//配置了http监听端口，就启动http服务
			try {
				new HttpServer(Config.HTTP_SERVER_PORT).start();
			} catch (Exception e) {
				LogUtil.error(e);
			}
		}
		
		LogUtil.log("tunel-server v2.0");
	}
}
